<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>编辑资料</title>
    {include file="common/linkcss" /}
</head>

<body>

    <div class="page__hd">
        <h1 class="page__title">{$card.name}的名片信息</h1>
        <p class="page__desc">编辑名片信息</p>
    </div>

    <form id="editCardForm">
        <div class="weui-cells__title">用户头像</div>
        <div class="weui-cells weui-cells_form" id="uploader">
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <div class="weui-uploader">
                        <div class="weui-uploader__bd">
                            {if $card.image}
                            <ul class="weui-uploader__files" id="uploaderFiles">
                                <li class="weui-uploader__file" id="uploadres" style="background-image:url(__UPLOADS__/{$card.image})"></li>
                            </ul>
                            {else/}
                            <ul class="weui-uploader__files" id="uploaderFiles">
                                <li class="weui-uploader__file" id="uploadres"></li>
                            </ul>
                            {/if}
                            <div class="weui-uploader__input-box">
                                <input id="upload" class="weui-uploader__input" type="file" accept="image/*" multiple="">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <input type="hidden" name="image" id="image" value="{$card.image}">


        <div class="weui-cells__title">名称</div>
        <div class="weui-cells">
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <input class="weui-input" type="text" name="name" value="{$card.name}" placeholder="请输入名称">
                </div>
            </div>
        </div>

        <div class="weui-cells__title">英文名称</div>
        <div class="weui-cells">
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <input class="weui-input" type="text" name="name_en" value="{$card.name_en}" placeholder="请输入英文名称">
                </div>
            </div>
        </div>

        {if session('adminLevel')}
        <div class="weui-cells__title">所属分公司</div>
        <div class="weui-cells">
            <div class="weui-cell weui-cell_select">
                <div class="weui-cell__bd">
                    <select class="weui-select" name="company_id">
                        <option value="0">请选择分公司</option>
                        {volist name="company" id="vo"}
                        {if $card['company_id']['id'] == $vo['id']}
                        <option value="{$vo.id}" selected>{$vo.title}</option>
                        {else/}
                        <option value="{$vo.id}">{$vo.title}</option>
                        {/if}
                        {/volist}
                    </select>
                </div>
            </div>
        </div>
        {/if}

        <div class="weui-cells__title">职位</div>
        <div class="weui-cells">
            <div class="weui-cell weui-cell_select">
                <div class="weui-cell__bd">
                    <select class="weui-select" name="job_id">
                        {volist name="job" id="vo"}
                        {if $card['job_id']['id'] == $vo['id']}
                        <option value="{$vo.id}" selected>{$vo.name}/{$vo.des}</option>
                        {else/}
                        <option value="{$vo.id}">{$vo.name}/{$vo.des}</option>
                        {/if}
                        {/volist}
                    </select>
                </div>
            </div>
        </div>

        <div class="weui-cells__title">手机号</div>
        <div class="weui-cells">
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <input class="weui-input" type="text" name="phone" value="{$card.phone}" placeholder="请输入手机号">
                </div>
            </div>
        </div>

        <div class="weui-cells__title">公司分号</div>
        <div class="weui-cells">
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <input class="weui-input" type="text" name="extension" value="{$card.extension}" placeholder="请输入公司分号">
                </div>
            </div>
        </div>

        <div class="weui-cells__title">邮箱</div>
        <div class="weui-cells">
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <input class="weui-input" type="text" name="email" value="{$card.email}" placeholder="请输入邮箱">
                </div>
            </div>
        </div>

        <div class="weui-cells__title">微信号</div>
        <div class="weui-cells">
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <input class="weui-input" type="text" name="wechat" value="{$card.wechat}" placeholder="请输入微信号">
                </div>
            </div>
        </div>

        <input type="hidden" name="cid" value="{$card.id}">
        <input type="hidden" name="gid" value="{$card.gid}">

        <div class="weui-btn-area">
            <input type="submit" id="editCardBtn" class="weui-btn weui-btn_primary" value="更新资料">
        </div>

        <div style="padding:30px;"></div>

    </form>


    <script>
        $('#editCardForm').submit(function () {
            $.post("{:url('card/edit')}",
                $('#editCardForm').serialize(),
                function (res) {
                    if (res) {
                        $.toast("修改名片成功");
                        setTimeout(function () {
                            window.location = "{:url('index/index',array('uid'=>$uid,'token'=>$token))}";
                        }, 1000);
                    } else {
                        $.toast("修改失败，请重试", "forbidden");
                    }
                });
            return false;
        });


        $('#upload').change(function () {
            var formData = new FormData();
            formData.append("file", $(this).get(0).files[0]);
            $.ajax({
                url: "{:url('index/upload')}",
                type: 'POST',
                data: formData,
                cache: false,
                contentType: false, //不可缺
                processData: false, //不可缺
                success: function (data) {
                    $('#uploadres').attr('style', 'background-image:url(__UPLOADS__/' + data + ')');
                    $('#image').val(data);
                }
            });
        })
    </script>
</body>

</html>